********************************************************************************

*This do-file produces all the results in the main text and appendix for "Window of Opportunity: War and the Origins of Parliament"

*5 April 2023

********************************************************************************
********************************************************************************
********************************************************************************

*Preamble

********************************************************************************
********************************************************************************
********************************************************************************

*Set Stata options

clear 
cap clear matrix
cap clear mata
set more off
cap set mat 800
cap set mem 500m

*Set directories

global maindirectory "C:\Dropbox\Window of Opportunity\Replication"
global rawdata "$maindirectory\raw_data"
global cleandata "$maindirectory\clean_data"
global output "$maindirectory\output"

********************************************************************************
********************************************************************************
********************************************************************************

*Results in Main Text

********************************************************************************
********************************************************************************
********************************************************************************

cd "$cleandata"
use "data_CDO_main", clear
xtset polity_id year

cd "$output"

cap log close
log using "make_output.log", text replace

********************************************************************************
*Table 1: The Communal Revolution and Parliamentary Births in Medieval Europe
********************************************************************************

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

*Produces century of first commune birth as listed in Column 2 of Table 1
*In "make_output.log", "1000" refers to 11th century, "1100" refers to 12th century, etc.
*Using the results in make_output.log, we made Table 1 in Word
*For further details about the construction methods and sources for Table 1, see the main text and Appendices B and C of Online Appendix

sort polity century
by polity: gen N=_n 
keep if N==1 /*keep one observation per polity*/
list polity first_century_commune parl_year /*display one observation per polity*/
restore

********************************************************************************
*Table 2: War and Parliamentary Birth Years
********************************************************************************

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

cap erase table2.txt
cap erase table2.xml

*Column 1
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25 using table2, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, No, SE Cluster, Polity)

*Column 2
xtreg parl_birth n_conflicts_25 politytrend1-politytrend47 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25 using table2, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity)	
	
*Column 3
xtreg parl_birth n_conflicts_25 ln_avg_chrfup politytrend1-politytrend47 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25 ln_avg_chrfup using table2, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity)	
restore	

clear	
	
********************************************************************************
*Figure 1: The Communal Revolution and Parliamentary Births in Medieval Europe
********************************************************************************

set graphics off
set scheme lean1
cd "$cleandata"
use "data_figure1", clear

generate pos=3
replace pos=2 if polity=="Naples"
replace pos=9 if polity=="Saxony"
replace pos=2 if polity=="Navarre"
replace pos=9 if polity=="Burgundy"
replace pos=9 if polity=="Prussia"
replace pos=9 if polity=="Ireland"
replace pos=9 if polity=="Portugal"
replace pos=6 if polity=="Castile"
replace pos=6 if polity=="Catalonia"
replace pos=9 if polity=="Denmark"
replace pos=9 if polity=="Guelders"
replace pos=9 if polity=="Hesse"
replace pos=9 if polity=="Brittany"
replace pos=9 if polity=="Pomerania"
replace pos=9 if polity=="Sweden"

twoway (scatter parl_year century_firstcommune, mlab(polity) mlabv(pos) mlabs(small) msym(smcircle_hollow) mlabc(black)) ///
	(lfit parl_year century_firstcommune, lc(red) lp(solid)) ///
	, scheme(lean1) ///
	legend(off) ///
	xtitle(Communal revolution (century)) ///
	ytitle(Parliamentary birth (year)) ///
	xlab(11 "11th" 12 "12th" 13 "13th" 14 "14th") ///
	ylab(1150(50)1550) 

cd "$output"
graph export figure1.png, as(png) width(2500) replace
cap graph close graph

********************************************************************************
********************************************************************************
********************************************************************************

*Results in Appendix

********************************************************************************
********************************************************************************
********************************************************************************

cd "$cleandata"
use "data_CDO_main", clear
xtset polity_id year

cd "$output"

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

********************************************************************************
*Table A.1: Replace Unit Fixed Effects with Fixed Effects by Region	           
********************************************************************************

cap erase tableA1.txt
cap erase tableA1.xml
	
*Column 1
reg parl_birth n_conflicts_25 south north east west y1000-y1599 if d_first_century_commune==1, vce(cluster polity_id)
outreg2 n_conflicts_25 using tableA1, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Region FE, Yes, Year FE, Yes, Polity Trends, No, SE Cluster, Polity)

*Column 2
reg parl_birth n_conflicts_25 south north east west politytrend1-politytrend47 y1000-y1599 if d_first_century_commune==1, vce(cluster polity_id)
outreg2 n_conflicts_25 using tableA1, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Region FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity)	
	
*Column 3
reg parl_birth n_conflicts_25 ln_avg_chrfup south north east west politytrend1-politytrend47 y1000-y1599 if d_first_century_commune==1, vce(cluster polity_id)
outreg2 n_conflicts_25 ln_avg_chrfup using tableA1, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Region FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity)	
	
********************************************************************************
*Table A.2: Include Polity-Year Observations prior to Communal Revolution
********************************************************************************
	
cap erase tableA2.txt
cap erase tableA2.xml

*Column 1
xtreg parl_birth n_conflicts_25 y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25 using tableA2, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, No, SE Cluster, Polity)	

*Column 2
xtreg parl_birth n_conflicts_25 politytrend1-politytrend47 y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25 using tableA2, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity)	
	
*Column 3
xtreg parl_birth n_conflicts_25 ln_avg_chrfup politytrend1-politytrend47 y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25 ln_avg_chrfup using tableA2, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity)	

restore	

********************************************************************************
*Table A.3: Alternative Parliamentary Birth Years: Made in Word                          
********************************************************************************

********************************************************************************
*Table A.4: Alternative Parliamentary Birth Years: Results                     
********************************************************************************

cap erase tableA4.txt
cap erase tableA4.xml

********************************************************************************
	
*Aragon

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1247 if polity=="Aragon" /*Alternative to 1348*/ 	
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.

*Column 1
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Aragon)	
restore	

********************************************************************************
	
*Castile

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1212 if polity=="Castile" /*Alternative to 1250*/ 
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.
	
*Column 2
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Castile)	
restore	
	
********************************************************************************
	
*Catalonia

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1214 if polity=="Catalonia" /*Alternative to 1228*/ 
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.
	
*Column 3
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Catalonia)	
restore	

********************************************************************************
	
*Navarre

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1300 if polity=="Navarre" /*Alternative to 1355*/ 
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.
	
*Column 4
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Navarre)	
restore	
	
********************************************************************************

*Piedmont

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1375 if polity=="Piedmont" /*Alternative to 1328*/ 
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.
	
*Column 5
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Piedmont)	
restore	
	
********************************************************************************

*Sicily

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1232 if polity=="Sicily" /*Alternative to 1283*/ 
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.

*Column 6
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Sicily)	
restore	

********************************************************************************

*Sweden

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1435 if polity=="Sweden" /*Alternative to 1523*/  
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.
	
*Column 7
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Sweden)	
restore	
	
********************************************************************************

*Wurttemberg

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

replace parl_year=1520 if polity=="Wurttemberg" /*Alternative to 1457*/  
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.
	
*Column 8
xtset polity_id year
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25  using tableA4, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Alt Start, Wurttemberg)	
restore	
	
********************************************************************************
*Table A.5: Alternative Conflict Participation Years                          
********************************************************************************

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

cap erase tableA5.txt
cap erase tableA5.xml

xtset polity_id year

*Column 1
xtreg parl_birth n_conflicts_5 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_5 using tableA5, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 2
xtreg parl_birth n_conflicts_10 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_10 using tableA5, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 3
xtreg parl_birth n_conflicts_15 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_15 using tableA5, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 4
xtreg parl_birth n_conflicts_20 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_20 using tableA5, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 5
xtreg parl_birth n_conflicts_30 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_30 using tableA5, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 6
xtreg parl_birth n_conflicts_35 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_35 using tableA5, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

	
********************************************************************************
*Table A.6: Alternative Conflict Participation Variable  
********************************************************************************

cap erase tableA6.txt
cap erase tableA6.xml

*Column 1
xtreg parl_birth d_conflicts_5 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 d_conflicts_5 using tableA6, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 2
xtreg parl_birth d_conflicts_10 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 d_conflicts_10 using tableA6, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 3
xtreg parl_birth d_conflicts_15 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 d_conflicts_15 using tableA6, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 4
xtreg parl_birth d_conflicts_20 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 d_conflicts_20 using tableA6, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 5
xtreg parl_birth d_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 d_conflicts_25 using tableA6, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 6
xtreg parl_birth d_conflicts_30 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 d_conflicts_30 using tableA6, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)

*Column 7
xtreg parl_birth d_conflicts_35 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 d_conflicts_35 using tableA6, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity)
	
restore	

********************************************************************************
*Table A.7: Data Averages                                                      
********************************************************************************

*10-year averages

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

*Drop the following since we will reproduce them below

drop parl_birth
drop y1000-y1599

*Make decadal panel

gen year10=.
forvalues i = 1000(10)1599{
	replace year10=`i' if year>=`i' & year<=`i'+9
}

*Make parliamentary births variable for 10-year averages

gen parl_year10=.
replace parl_year10=1310 if polity=="Brabant"  /*1312*/
replace parl_year10=1350 if polity=="Brittany" /*1352*/
replace parl_year10=1300 if polity=="Flanders" /*1304*/
replace parl_year10=1420 if polity=="Guelders" /*1423*/
replace parl_year10=1250 if polity=="Lorraine" /*1251*/
replace parl_year10=1290 if polity=="Pomerania" /*1295*/
replace parl_year10=1320 if polity=="Scotland" /*1326*/
replace parl_year10=1340 if polity=="Aragon" /*1348*/
replace parl_year10=1220 if polity=="Catalonia" /*1228*/
replace parl_year10=1280 if polity=="Valencia" /*1283*/
replace parl_year10=1180 if polity=="Leon" /*1188*/
replace parl_year10=1350 if polity=="Navarre" /*1355*/
replace parl_year10=1160 if polity=="Lucca" /*1160*/
replace parl_year10=1350 if polity=="Papal States" /*1357*/
replace parl_year10=1280 if polity=="Sicily" /*1283*/
replace parl_year10=1340 if polity=="Bavaria" /*1347*/
replace parl_year10=1430 if polity=="Bohemia" /*1435*/
replace parl_year10=1380 if polity=="Hesse" /*1387*/
replace parl_year10=1290 if polity=="Ireland"  /*1299*/
replace parl_year10=1500 if polity=="Palatinate" /*1505*/
replace parl_year10=1350 if polity=="Sardinia" /*1355*/
replace parl_year10=1250 if polity=="Cologne" /*1259*/
replace parl_year10=1170 if polity=="Siena" /*1176*/
replace parl_year10=1280 if polity=="Florence" /*1284*/
replace parl_year10=1540 if polity=="Holland" /*1542*/
replace parl_year10=1450 if polity=="Wurttemberg" /*1457*/
replace parl_year10=1090 if polity=="Genoa" /*1099*/
replace parl_year10=1350 if polity=="Burgundy" /*1352*/
replace parl_year10=1430 if polity=="Saxony" /*1438*/
replace parl_year10=1400 if polity=="Austria" /*1402*/
replace parl_year10=1320 if polity=="Piedmont" /*1328*/
replace parl_year10=1440 if polity=="Naples" /*1444*/
replace parl_year10=1170 if polity=="Venice" /*1172*/
replace parl_year10=1250 if polity=="Portugal" /*1254*/
replace parl_year10=1320 if polity=="Prussia" /*1324*/
replace parl_year10=1460 if polity=="Denmark"   /*1468*/
replace parl_year10=1260 if polity=="England" /*1265*/
replace parl_year10=1520 if polity=="Sweden" /*1523*/
replace parl_year10=1390 if polity=="Hungary" /*1397*/
replace parl_year10=1250 if polity=="Castile" /*1250*/
replace parl_year10=1300 if polity=="France" /*1302*/
replace parl_year10=1460 if polity=="Poland" /*1468*/
replace parl_year10=1590 if polity=="Norway" /*1591*/ 

gen parl_birth=parl_year10==year10
replace parl_birth=. if year10>parl_year10 & parl_year10!=.
replace parl_birth=0 if parl_year10==.

*Collapse data

collapse(mean) parl_birth n_conflicts d_first_century_commune, by(polity_id year10) 

sort polity_id year10

tab year10, gen(yy)

cap erase tableA7.txt
cap erase tableA7.xml

xtset polity_id year10
xtreg parl_birth n_conflicts yy* if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts using tableA7, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Time FE, Yes, SE Cluster, Polity, Granularity, 10yr)	

restore	
	
********************************************************************************

*20-year averages

preserve

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

*Drop the following since we will reproduce them below

drop parl_birth
drop y1000-y1599

*Make bi-decadal panel

gen year20=.
forvalues i = 1000(20)1599{
	replace year20=`i' if year>=`i' & year<=`i'+19
}

*Make parliamentary births variable for 20-year averages

gen parl_year20=.
replace parl_year20=1300 if polity=="Brabant"  /*1312*/
replace parl_year20=1340 if polity=="Brittany" /*1352*/
replace parl_year20=1300 if polity=="Flanders" /*1304*/
replace parl_year20=1420 if polity=="Guelders" /*1423*/
replace parl_year20=1240 if polity=="Lorraine" /*1251*/
replace parl_year20=1280 if polity=="Pomerania" /*1295*/
replace parl_year20=1320 if polity=="Scotland" /*1326*/
replace parl_year20=1340 if polity=="Aragon" /*1348*/
replace parl_year20=1220 if polity=="Catalonia" /*1228*/
replace parl_year20=1280 if polity=="Valencia" /*1283*/
replace parl_year20=1180 if polity=="Leon" /*1188*/
replace parl_year20=1340 if polity=="Navarre" /*1355*/
replace parl_year20=1160 if polity=="Lucca" /*1160*/
replace parl_year20=1340 if polity=="Papal States" /*1357*/
replace parl_year20=1280 if polity=="Sicily" /*1283*/
replace parl_year20=1340 if polity=="Bavaria" /*1347*/
replace parl_year20=1420 if polity=="Bohemia" /*1435*/
replace parl_year20=1380 if polity=="Hesse" /*1387*/
replace parl_year20=1280 if polity=="Ireland"  /*1299*/
replace parl_year20=1500 if polity=="Palatinate" /*1505*/
replace parl_year20=1340 if polity=="Sardinia" /*1355*/
replace parl_year20=1240 if polity=="Cologne" /*1259*/
replace parl_year20=1160 if polity=="Siena" /*1176*/
replace parl_year20=1280 if polity=="Florence" /*1284*/
replace parl_year20=1540 if polity=="Holland" /*1542*/
replace parl_year20=1440 if polity=="Wurttemberg" /*1457*/
replace parl_year20=1080 if polity=="Genoa" /*1099*/
replace parl_year20=1340 if polity=="Burgundy" /*1352*/
replace parl_year20=1420 if polity=="Saxony" /*1438*/
replace parl_year20=1400 if polity=="Austria" /*1402*/
replace parl_year20=1320 if polity=="Piedmont" /*1328*/
replace parl_year20=1440 if polity=="Naples" /*1444*/
replace parl_year20=1160 if polity=="Venice" /*1172*/
replace parl_year20=1240 if polity=="Portugal" /*1254*/
replace parl_year20=1320 if polity=="Prussia" /*1324*/
replace parl_year20=1460 if polity=="Denmark"   /*1468*/
replace parl_year20=1260 if polity=="England" /*1265*/
replace parl_year20=1520 if polity=="Sweden" /*1523*/
replace parl_year20=1380 if polity=="Hungary" /*1397*/
replace parl_year20=1240 if polity=="Castile" /*1250*/
replace parl_year20=1300 if polity=="France" /*1302*/
replace parl_year20=1460 if polity=="Poland" /*1468*/
replace parl_year20=1580 if polity=="Norway" /*1591*/ 

gen parl_birth=parl_year20==year20
replace parl_birth=. if year20>parl_year20 & parl_year20!=.
replace parl_birth=0 if parl_year20==.

*Collapse data

collapse(mean) parl_birth n_conflicts d_first_century_commune, by(polity_id year20)

sort polity_id year20
tab year20, gen(yy)
	
xtset polity_id year20
xi: xtreg parl_birth n_conflicts yy* if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts using tableA7, st(coef se) paren(se) bdec(3) nocon excel ///
	addtext(Polity FE, Yes, Time FE, Yes, SE Cluster, Polity, Granularity, 20yr)
restore

********************************************************************************
*Table A.8: Parliamentary Birth Years: City-States: Made in Word         
********************************************************************************

********************************************************************************
*Table A.9: Include City-States                                                
********************************************************************************

cap erase tableA9.txt
cap erase tableA9.xml

xtset polity_id year
			
*Column 1
xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25 using tableA9, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, No, SE Cluster, Polity, Method, OLS, City States, Yes)

*Column 2
xtreg parl_birth n_conflicts_25 politytrend1-politytrend47 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25 using tableA9, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity, Method, OLS, City States, Yes)	
	
*Column 3
xtreg parl_birth n_conflicts_25 ln_avg_chrfup politytrend1-politytrend47 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)
outreg2 n_conflicts_25 ln_avg_chrfup using tableA9, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, Polity Trends, Yes, SE Cluster, Polity, Method, OLS, City States, Yes)	
	
clear	
	
********************************************************************************
*Table A.10: Alternative Conflict Data
********************************************************************************

cd "$cleandata"
use "data_kokkonen_sundell", clear

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

cd "$output"
cap erase tableA10.txt
cap erase tableA10.xml

*We lose more than 50 percent of the polity sample and more than 60 percent of the total observations after merging our data with the Kokkonen-Sundell data
*Given this large data loss, we include polity-year observations prior to the communal revolution for the regressions in Appendix Tables A.10 and A.11, in order to preserve as many observations as possible

xtset polity_id year

*Column 1
xtreg parl_birth n_conflicts_25_ks y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25_ks using tableA10, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Method, OLS)

*Column 2
xtreg parl_birth n_conflicts_25_ksb y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25_ksb using tableA10, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Method, OLS)

********************************************************************************
*Table A.11: Controls for Primogeniture, Successions, and Heirs
********************************************************************************

cap erase tableA11.txt
cap erase tableA11.xml

*Column 1
xtreg parl_birth n_conflicts_25_ks naturaldeath y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25_ks naturaldeath using tableA11, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Method, OLS)

*Column 2
xtreg parl_birth n_conflicts_25_ks noheir y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25_ks noheir using tableA11, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Method, OLS)

*Column 3
xtreg parl_birth n_conflicts_25_ks naturaldeath noheir natdeath_noheir y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25_ks naturaldeath noheir natdeath_noheir using tableA11, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Method, OLS)

*Column 4
xtreg parl_birth n_conflicts_25_ks naturaldeath noheir natdeath_noheir primogeniture natdeath_primo y1000-y1599, fe vce(cluster polity_id)
outreg2 n_conflicts_25_ks naturaldeath noheir natdeath_noheir primogeniture primo_noheir using tableA11, st(coef se) paren(se) bdec(3) nocon excel  ///
	addtext(Polity FE, Yes, Year FE, Yes, SE Cluster, Polity, Method, OLS)

clear

********************************************************************************
*Figure A.1: Exclude Polities One by One
********************************************************************************

cd "$cleandata"
use "data_CDO_main", clear

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

preserve

gen id=0
replace id=1 if polity=="Aragon" 
replace id=2 if polity=="Austria" 
replace id=3 if polity=="Bavaria" 
replace id=4 if polity=="Bohemia" 
replace id=5 if polity=="Brabant" 
replace id=6 if polity=="Brittany" 
replace id=7 if polity=="Burgundy" 
replace id=8 if polity=="Castile" 
replace id=9 if polity=="Catalonia" 
replace id=10 if polity=="Denmark" 
replace id=11 if polity=="England" 
replace id=12 if polity=="Flanders" 
replace id=13 if polity=="France" 
replace id=14 if polity=="Guelders" 
replace id=15 if polity=="Hesse" 
replace id=16 if polity=="Holland" 
replace id=17 if polity=="Hungary" 
replace id=18 if polity=="Ireland" 
replace id=19 if polity=="Leon"  
replace id=20 if polity=="Lorraine" 
replace id=21 if polity=="Naples" 
replace id=22 if polity=="Navarre" 
replace id=23 if polity=="Norway" 
replace id=24 if polity=="Palatinate" 
replace id=25 if polity=="Papal States" 
replace id=26 if polity=="Piedmont" 
replace id=27 if polity=="Poland" 
replace id=28 if polity=="Pomerania" 
replace id=29 if polity=="Portugal" 
replace id=30 if polity=="Prussia"  
replace id=31 if polity=="Sardinia" 
replace id=32 if polity=="Saxony"
replace id=33 if polity=="Scotland"
replace id=34 if polity=="Sicily"
replace id=35 if polity=="Sweden"
replace id=36 if polity=="Valencia"	
replace id=37 if polity=="Wurttemberg"	
	
order id	

local statelocal "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37"	
	
foreach p of local statelocal {
    xtset polity_id year
	qui xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1 & id!=`p', fe vce(cluster polity_id)
	parmest, le(95) sa("nopolity_`p'.dta", replace)
}	
	
foreach p of local statelocal {
	use "nopolity_`p'.dta", clear
	gen N=_n
	keep if N==1
	gen droppolity="`p'"
	keep parm estimate min95 max95 droppolity
	save, replace
}	
	
local statelocal "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37"
use "nopolity_1.dta", clear
foreach p of local statelocal {
	append using "nopolity_`p'.dta"
	}
drop in 1

order droppolity
destring droppolity, replace
	
label define yaxis ///
1 "Aragon" ///
2 "Austria" ///
3 "Bavaria" ///
4 "Bohemia" ///
5 "Brabant" ///
6 "Brittany" ///
7 "Burgundy" ///
8 "Castile" ///
9 "Catalonia" ///
10 "Denmark" ///
11 "England" ///
12 "Flanders" ///
13 "France" ///
14 "Guelders" ///
15 "Hesse" ///
16 "Holland" ///
17 "Hungary" ///
18 "Ireland" ///
19 "Leon" /// 
20 "Lorraine" ///
21 "Naples" ///
22 "Navarre" ///
23 "Norway" ///
24 "Palatinate" ///
25 "Papal States" ///
26 "Piedmont" ///
27 "Poland" ///
28 "Pomerania" ///
29 "Portugal" ///
30 "Prussia" /// 
31 "Sardinia" ///
32 "Saxony" ///
33 "Scotland" ///
34 "Sicily" ///
35 "Sweden" ///
36 "Valencia" ///
37 "Wurttemberg"
label values droppolity yaxis

save "nopolity.dta", replace	

twoway (rcap min95 max95 droppolity, horizontal) ///
	(scatter droppolity estimate, msymbol(oh)) ///
	, scheme(lean1) ///
	legend(off) ///
	xscale(range(-0.02 0.08)) xlabel(-0.02(0.02) 0.08) xtitle("95% Confidence Interval") ///
	xline(0, lpattern(solid)) ///
	yscale(range(1 37)) yscale(reverse) ylabel(1(1)37, valuelabel labsize(vsmall) angle(0)) ytick(1(1)37) ytitle("Excluded Polity") 

cd "$output"
graph export figureA1.png, as(png) width(2500) replace
cap graph close graph	
restore

********************************************************************************
********************************************************************************
********************************************************************************

*Other Results (mentioned but not reported in main text)

********************************************************************************
********************************************************************************
********************************************************************************

********************************************************************************
*Supplementary results described in Section 3.4
*Details provided below
********************************************************************************

*Produces supplementary results described in text of Section 3.4

tabstat parl_year if first_century_commune==1000, s(median n) 
tabstat parl_year if first_century_commune==1100, s(median n) 
tabstat parl_year if first_century_commune==1200, s(median n) 
tabstat parl_year if first_century_commune==1300, s(median n) 

*Produces supplementary result described in Footnote 4 of Section 3.4

preserve
sort polity century
by polity century: gen N=_n /*keep one observation per polity-century given that our conflict dataset is yearly*/
keep if N==1

reg parl_year first_century_commune, r

restore

********************************************************************************
*Supplementary result described in Footnote 10 of Section 5
*Replace benchmark parliamentary birth year for England (i.e. 1265) with 1254
********************************************************************************

preserve
replace parl_year=1254 if polity=="England" /*Alternative to 1265*/ 	
drop parl_birth
gen parl_birth=parl_year==year
replace parl_birth=. if year>parl_year
replace parl_birth=0 if parl_year==.

xtreg parl_birth n_conflicts_25 y1000-y1599 if d_first_century_commune==1, fe vce(cluster polity_id)

restore	

clear

********************************************************************************
*Supplementary result described in Footnote 3 of Section 3.3
*Reproduces Table 1 with Euratlas matching
********************************************************************************

cd "$cleandata"
use "data_euratlas.dta", clear

drop if italiancitystate==1 /*exclude city-states in Italy*/
drop if polity=="Cologne" /*exclude city-state in Germany*/

list polity first_century_commune parl_year /*the annotations for Table 1 above also apply here*/

clear
log close
